package com.markyao.recos;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.CopyOnWriteArraySet;

@Configuration
public class RecosCoreConfig {

    /**
     * 连接Key的set： 每个appName都有对应的一条set
     * @return
     */
    @Bean("connectSet")
    public Map<String, Set<String>>connectSet(){
        Map<String,Set<String>>connectSet=new ConcurrentHashMap<>();
        return connectSet;
    }

    /**
     * 服务提供者map表: 不同的interfaceName有不同的提供者,其中包含url和weight权重值
     * @return
     */
    @Bean(name = "providersMap")
    public Map<String,Map<String,String>>providersMap(){
        Map<String,Map<String,String>>providersMap=new ConcurrentHashMap<>();
        return providersMap;
    }

    /**
     * 不同的appName具备自己的一条引用set列表
     * @return
     */
    @Bean("refrenceRegistrySet")
    public Map<String,Set<String>>refrenceRegistrySet(){
        Map<String,Set<String>>refrenceRegistrySet=new ConcurrentHashMap<>();
        return refrenceRegistrySet;
    }

    /**
     * 不同的app具备自己的一个map表（包含基本信息）
     * @return
     */
    @Bean("serverRegistryMap")
    public Map<String,Map<String,String>>serverRegistryMap(){
        Map<String,Map<String,String>>serverRegistryMap=new ConcurrentHashMap<>();
        return serverRegistryMap;
    }

    /**
     * 不同的Appname具备自己的一个kv -> 包含了interfacename:implname
     * @return
     */
    @Bean("serviceRegistryMap")
    public Map<String,Map<String,String>>serviceRegistryMap(){
        Map<String,Map<String,String>>serviceRegistryMap=new ConcurrentHashMap<>();
        return serviceRegistryMap;
    }

    /**
     * url和appName的映射表
     * @return
     */
    @Bean("urlMap")
    public Map<String,String>urlMap(){
        Map<String,String>urlMap=new ConcurrentHashMap<>();
        return urlMap;
    }

    /**
     * 心跳表: k是appname+url v:ttl值
     * @return
     */
    @Bean("heartBeatMap")
    public Map<String,Long>heartBeatMap(){
        Map<String,Long>heartBeatMap=new ConcurrentHashMap<>();
        return heartBeatMap;
    }
    @Bean("heartBeatMap0")
    public Map<String,Long>heartBeatMap0(){
        Map<String,Long>heartBeatMap0=new ConcurrentHashMap<>();
        return heartBeatMap0;
    }

    /**
     * k:url v:timeStamp
     * @return
     */
    @Bean("errorUrlMap")
    public Map<String,String>errorUrlMap(){
        Map<String,String>errorUrlMap=new ConcurrentHashMap<>();
        return errorUrlMap;
    }

    @Bean("killConnectKeys")
    public Map<String,Set<String>>killConnectKeys(){
        Map<String,Set<String>>killConnectKeys=new ConcurrentHashMap<>();
        return killConnectKeys;
    }

    @Bean("reconnectKeys")
    public Map<String,Set<String>>reconnectKeys(){
        Map<String,Set<String>>reconnectKeys=new ConcurrentHashMap<>();
        return reconnectKeys;
    }

    /**
     * 每个注册进来的key都会保存到此
     * @return
     */
    @Bean("serverKeySet")
    public Set<String>serverKeySet(){
        return new HashSet<>();
    }

    @Bean("serviceConfMap")
    public Map<String,Map<String,String>>serviceConfMap(){
        return new ConcurrentHashMap<>();
    }

    @Bean("refreshConfAdviceSet")
    public Map<String,Object>refreshConfAdviceSet(){
        return new ConcurrentHashMap<>();
    }

    @Bean("appsDataId")
    public Map<String,Set<String>>appsDataId(){
        Map<String,Set<String>>appsDataId=new ConcurrentHashMap<>();
        return appsDataId;
    }

    @Bean("healthMap")
    public Map<String,String> healthMap(){
        return new ConcurrentHashMap<>();
    }
}
